<template>
  <div class="confirm-box">
    <div class="main">
      <div class="title">
        {{ title }}
      </div>
      <div class="button">
        <button class="cancel" @click="cancel">{{ cancelText }}</button>
        <button class="confirm" @click="confirm">{{ confirmText }}</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      title: '你确定要删除吗',
      confirmText: '确认',
      cancelText: '取消'
    };
  },
  methods: {
    show() {
      return new Promise(resolve => {
        this.resolve = resolve;
      });
    },
    confirm() {
      this.resolve('confirm');
      this.hide();
    },
    cancel() {
      this.resolve('cancel');
      this.hide();
    },
    hide() {
      this.$el.parentNode.removeChild(this.$el);
      this.$destroy();
    }
  }
};
</script>

<style scoped>
.confirm-box {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  background-color: rgba(0, 0, 0, 0.5);
}
.main {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  min-width: 75%;
  padding: 10px;
  border-radius: 5px;
  background-color: #fff;
}
.title {
  margin-bottom: 15px;
}
.button {
  float: right;
}
.button button {
  border: none;
  margin-left: 10px;
  padding: 5px 15px;
  border-radius: 5px;
  color: #fff;
}
.confirm {
  background: #66b1ff;
}
.cancel {
  background: lightcoral;
}
</style>
